using System;
using System.ComponentModel;
using System.Collections.Generic;

using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

using SBPweb.Modules.Logging;
using SBPweb.Localization;

namespace SBPweb.Presentation.Windows.Forms.Host
{
	public class LogManager : SBPweb.Modules.Logging.LogManagerBase
    {

        private LoggingSettings pSettings;

        #region Constructor logic

        internal LogManager()
		{
            pSettings = System.Configuration.ConfigurationManager.GetSection("loggingConfiguration") as LoggingSettings;
        }

        #endregion

        #region Public properties

        [ReadOnly(true)]
        public override ICollection<string> Categories
        {
            get
            {
                ICollection<string> ret = new List<string>(pSettings.TraceSources.Count);
                foreach (TraceSourceData tsd in pSettings.TraceSources)
                {
                    ret.Add(tsd.Name);
                }
                return ret;
            }
        }

        #endregion

        #region Methods

        public override void Initialize()
        {
            SBPweb.Logging.LogManager.Initialize();
			WriteInfo(this, "Logger has been initialized.", "Logger"); 
        }

        public override void Terminate()
        {
			WriteInfo(this, "The logger needs to be finalized.", "Logger");
            SBPweb.Logging.LogManager.Terminate();
        }

        public override void Write(object sender, object obj, string category)
        {
            base.Write(sender, obj, category);
            SBPweb.Logging.LogManager.Write(obj, category);
        }

        public override void WriteCritical(object sender, object obj, string category)
        {
            base.WriteCritical(sender, obj, category);
            SBPweb.Logging.LogManager.WriteCritical(obj, category);
        }

        public override void WriteError(object sender, object obj, string category)
        {
            base.WriteError(sender, obj, category);
            SBPweb.Logging.LogManager.WriteError(obj, category);
        }

        public override void WriteInfo(object sender, object obj, string category)
        {
            base.WriteInfo(sender, obj, category);
            SBPweb.Logging.LogManager.WriteInfo(obj, category);
        }

        public override void WriteVerbose(object sender, object obj, string category)
        {
            base.WriteVerbose(sender, obj, category);
            SBPweb.Logging.LogManager.WriteVerbose(obj, category);
        }

        public override void WriteWarning(object sender, object obj, string category)
        {
            base.WriteWarning(sender, obj, category);
            SBPweb.Logging.LogManager.WriteWarning(obj, category);
        }

        #endregion

    }
}
